home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hiarcmen / loadme2.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  10.1 KB  |  246 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. --*******************************************************************************
  3. --*          Demo for:    MenuButton
  4. --*    Required files: reqFiles/button.sx
  5. --*                    bmpmenu.sx
  6. --*            Author:    Su Quek - Kaleida Labs, Inc.
  7. --*-----------------------------------------------------------------------------*
  8. --*       Description: This script demonstrates how to create a hierarchical
  9. --*                    menu using bitmaps.
  10. --*                    When you run "bmpmenu.sxt", you should see a window
  11. --*                    with a settings menu with the following menu structure:
  12. --*
  13. --*                        Settings - Reset
  14. --*                                 - Color - Fill   - Red
  15. --*                                                  - Green
  16. --*                                                  - Blue
  17. --*                                         - Stroke - Red
  18. --*                                                  - Green
  19. --*                                                  - Blue
  20. --*
  21. --*******************************************************************************
  22.  
  23. module BitmapMenuModule
  24.     uses ScriptX
  25. end
  26.  
  27. in module BitmapMenuModule
  28.  
  29. --*=============================================================================*
  30. --* Set up DirReps
  31. --*=============================================================================*
  32. global demoDir := theScriptDir
  33. global mediaDir := spawn theScriptDir "media"
  34. global reqFilesDir := spawn theScriptDir "reqfiles"
  35.  
  36. --*=============================================================================*
  37. --* Load required files
  38. --*=============================================================================*
  39. -- Load Button
  40. fileIn reqFilesDir name:"button.sx"
  41.  
  42. -- Load MenuButton
  43. fileIn demoDir name:"bmpmenu.sx"
  44.  
  45. --*=============================================================================*
  46. --*    Define Demo 
  47. --*=============================================================================*
  48. class Demo (Window)
  49. end
  50.  
  51. --*=============================================================================*
  52. --*       Method name:    importBitmap
  53. --*             Class:    Demo
  54. --*             Usage: importBitmap self mediaDir bitmapFile
  55. --*                        mediaDir    - DirRep
  56. --*                        bitmapFile  - String object
  57. --*-----------------------------------------------------------------------------*
  58. --*       Description: Imports the given bitmap from the given directory.
  59. --*=============================================================================*
  60. method importBitmap self {class Demo} mediaDir bitmapFile ->
  61. (
  62.     local theStream := getStream mediaDir bitmapFile @readable
  63.     local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap
  64.     local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
  65.                     colormap:theColormap container:self.title
  66.     return theBMP
  67. )
  68.  
  69. --*=============================================================================*
  70. --*       Method name:    makeMenu
  71. --*             Class:    Demo
  72. --*             Usage: makeMenu self 
  73. --*-----------------------------------------------------------------------------*
  74. --*       Description: Makes the menu and its submenus.
  75. --*=============================================================================*
  76. method makeMenu self {class Demo} ->
  77. (
  78.     --*=========================================================================*
  79.     --* Import all required bitmaps
  80.     --*=========================================================================*
  81.     local mediaDir := spawn theScriptDir "media"
  82.     local setRelBitmap := (importBitmap self mediaDir "setrel.bmp")
  83.     local resetRelBitmap := (importBitmap self mediaDir "resetrel.bmp")
  84.     local colorRelBitmap := (importBitmap self mediaDir "colorrel.bmp")
  85.     local fillRelBitmap := (importBitmap self mediaDir "fillrel.bmp")
  86.     local strokRelBitmap := (importBitmap self mediaDir "strokrel.bmp")
  87.     local redRelBitmap := (importBitmap self mediaDir "redrel.bmp")
  88.     local greenRelBitmap := (importBitmap self mediaDir "greenrel.bmp")
  89.     local blueRelBitmap := (importBitmap self mediaDir "bluerel.bmp")
  90.  
  91.  
  92.     local setPrsBitmap := (importBitmap self mediaDir "setprs.bmp")
  93.     local resetPrsBitmap := (importBitmap self mediaDir "resetprs.bmp")
  94.     local colorPrsBitmap := (importBitmap self mediaDir "colorprs.bmp")
  95.     local fillPrsBitmap := (importBitmap self mediaDir "fillprs.bmp")
  96.     local strokPrsBitmap := (importBitmap self mediaDir "strokprs.bmp")
  97.     local redPrsBitmap := (importBitmap self mediaDir "redprs.bmp")
  98.     local greenPrsBitmap := (importBitmap self mediaDir "greenprs.bmp")
  99.     local bluePrsBitmap := (importBitmap self mediaDir "blueprs.bmp")
  100.  
  101.  
  102.     --*=========================================================================*
  103.     --* Create the settings menu
  104.     --* Note: the 'supermenu' keyword is 'undefined'
  105.     --*=========================================================================*
  106.     local settingsMenu := new MenuButton supermenu:undefined \
  107.                                      releasedBitmap:setRelBitmap \
  108.                                      pressedBitmap:setPrsBitmap
  109.                                          
  110.     --*=========================================================================*
  111.     --* Create the reset item under the settings menu
  112.     --*=========================================================================*
  113.     addmenuitem settingsMenu resetRelBitmap resetPrsBitmap self (authordata me -> \
  114.             authordata.fill := authordata.stroke := blackBrush)
  115.  
  116.     
  117.     --*=========================================================================*
  118.     --* Create the color sub-menu
  119.     --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
  120.     --*          i.e. settingsMenu
  121.     --*=========================================================================*
  122.     local colorMenu := new MenuButton supermenu:settingsMenu \
  123.                                      placement:@menuRight \
  124.                                      releasedBitmap:colorRelBitmap \
  125.                                      pressedBitmap:colorPrsBitmap
  126.  
  127.     --*=========================================================================*
  128.     --* Create the fill sub-sub-menu
  129.     --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
  130.     --*          i.e. colorMenu
  131.     --*=========================================================================*
  132.     local fillMenu := new MenuButton supermenu:colorMenu \
  133.                                      placement:@menuRight \
  134.                                      releasedBitmap:fillRelBitmap \
  135.                                      pressedBitmap:fillPrsBitmap
  136.  
  137.     --*=========================================================================*
  138.     --* Create the red, green and blue items under the fill menu
  139.     --*=========================================================================*
  140.     addmenuitem fillMenu redRelBitmap redPrsBitmap self (authordata me ->  \
  141.             authordata.fill := (new Brush color:redColor))
  142.     addmenuitem fillMenu greenRelBitmap greenPrsBitmap self (authordata me -> \
  143.             authordata.fill := (new Brush color:greenColor))
  144.     addmenuitem fillMenu blueRelBitmap bluePrsBitmap self (authordata me -> \
  145.             authordata.fill := (new Brush color:blueColor))
  146.     
  147.     
  148.     --*=========================================================================*
  149.     --* Create the stroke sub-sub-menu
  150.     --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
  151.     --*          i.e. colorMenu
  152.     --*=========================================================================*
  153.     local strokeMenu := new MenuButton supermenu:colorMenu \
  154.                                      placement:@menuRight \
  155.                                      releasedBitmap:strokRelBitmap \
  156.                                      pressedBitmap:strokPrsBitmap
  157.  
  158.     --*=========================================================================*
  159.     --* Create the red, green and blue items under the fill menu
  160.     --*=========================================================================*
  161.     addmenuitem strokeMenu redRelBitmap redPrsBitmap self (authordata me ->  \
  162.             authordata.stroke := (new Brush color:redColor))
  163.     addmenuitem strokeMenu greenRelBitmap greenPrsBitmap self (authordata me -> \
  164.             authordata.stroke := (new Brush color:greenColor))
  165.     addmenuitem strokeMenu blueRelBitmap bluePrsBitmap self (authordata me -> \
  166.             authordata.stroke := (new Brush color:blueColor))
  167.  
  168.     return settingsMenu
  169. )
  170.  
  171.  
  172. --*=============================================================================*
  173. --*       Method name:    init
  174. --*             Class:    Demo
  175. --*             Usage: init self 
  176. --*-----------------------------------------------------------------------------*
  177. --*       Description: Creates a 200x200 window.
  178. --*=============================================================================*
  179. method init self {class Demo} #rest args ->
  180. (
  181.     -- Create a 200x200 window 
  182.     apply nextMethod self boundary:(new Rect x2:200 y2:200) \
  183.                           centered:true \
  184.                           fill:blackBrush \
  185.                           stroke:blackBrush \
  186.                           name:"Select from Menu" args
  187.     return self
  188. )
  189.  
  190.  
  191. --*=============================================================================*
  192. --*       Method name:    afterInit
  193. --*             Class:    Demo
  194. --*             Usage: afterInit self 
  195. --*-----------------------------------------------------------------------------*
  196. --*       Description: Makes the menu and appends it to the demo window.
  197. --*=============================================================================*
  198. method afterInit self {class Demo} #rest args ->
  199. (        
  200.     --*=========================================================================*
  201.     --* Create an actuator controller to control all the buttons in the demo
  202.     --*    window.
  203.     --*=========================================================================*
  204.     new ActuatorController space:self wholespace:true
  205.     
  206.     --*=========================================================================*
  207.     --* Add menu to the demo window and display it
  208.     --*=========================================================================*
  209.     prepend self (makeMenu self)
  210.     show self
  211.     
  212.     return self
  213. )
  214.  
  215.  
  216. --*=============================================================================*
  217. --*    Create a title container
  218. --*=============================================================================*
  219. object tc (TitleContainer)
  220.     dir        : theScriptDir
  221.     path    : "bmpmenu.sxt" 
  222.     name    : "Hierarchical Bitmap Menu"
  223. end        
  224.         
  225. --*=============================================================================*
  226. --*    Create demo
  227. --*=============================================================================*
  228. object win (Demo)
  229.     title:tc
  230. end
  231.  
  232. --*=============================================================================*
  233. --*    Undefine global DirReps
  234. --*=============================================================================*
  235. demoDir := undefined
  236. mediaDir := undefined
  237. reqFilesDir := undefined
  238.  
  239. --*=============================================================================*
  240. --*    Store module in the title container
  241. --*=============================================================================*
  242. append tc (getModule @BitmapMenuModule)
  243. tc.startUpAction := (tc -> load tc[1]
  244.                            show win)
  245. close tc
  246. -->>>